from flask_wtf import FlaskForm
from wtforms import *
from wtforms.validators import DataRequired, Required, ValidationError, Length, EqualTo, Email, InputRequired


class BaseFrom(FlaskForm):
    def get_error(self):
        return self.errors.popitem()[1][0]


class LoginForm(BaseFrom):
    email = StringField(
        validators=[DataRequired(message="请输入用户名"),
                    Length(6, 18, message="用户名最少6位，最多18位")]
    )
    password = PasswordField(
        validators=[DataRequired(message="请输入密码"),
                    Length(8, 20, message='密码最少8位，最多20位')]
    )
    remember = IntegerField()


class ResetpwdForm(BaseFrom):
    old_pwd = PasswordField(
        validators=[DataRequired(message='请输入正确的旧密码'),
                    Length(8, 20, message='密码最少8位，最多20位')]
    )
    new_pwd1 = PasswordField(
        validators=[DataRequired(message='请输入新密码'),
                    Length(8, 20, message='密码最少8位，最多20位')]
    )
    new_pwd2 = PasswordField(
        validators=[DataRequired(message='请输入新密码'),
                    EqualTo('new_pwd1', message='新密码两次输入不一致')]
    )


class ResetEmailForm(BaseFrom):
    old_email = StringField(
        validators=[DataRequired(message='请输入旧邮箱'),
                    Email('请输入正确格式的旧邮箱')]
    )
    new_email = StringField(
        validators=[DataRequired('请输入新邮箱'),
                    Email('请输入正确格式的新邮箱')]
    )


class BannerFrom(BaseFrom):
    img_name = StringField(
        label='图片名称',
        validators=[DataRequired(message="请输入轮播图名称")]
    )
    img_url = StringField(
        label='图片地址',
        validators=[DataRequired(message="请输入轮播图地址")]
    )
    link_url = StringField(
        label='跳转链接',
        validators=[DataRequired(message='请输入跳转链接')]
    )
    priority = StringField(
        label='请输入优先级',
        validators=[DataRequired(message="请输入优先级")]
    )


class EditBannerForm(BannerFrom):
    banner_id = IntegerField(
        label='轮播图ID',
        validators=[InputRequired(message='请输入轮播图ID号码')]
    )


class DeleteBanner(BaseFrom):
    banner_id = IntegerField(
        label='轮播图ID',
        validators=[InputRequired(message='请输入轮播图ID号码')]
    )


class BorderForm(BaseFrom):
    board_name = StringField(
        label='板块名称',
        validators=[InputRequired(message='请输入板块名称')]
    )


class EditBoard(BorderForm):
    board_id = IntegerField(
        label='板块ID',
        validators=[InputRequired(message='未发送板块ID')]
    )


class DeleteBoard(BaseFrom):
    board_id = IntegerField(
        label='板块ID',
        validators=[InputRequired(message='未发送板块ID')]
    )


class AddHighLight(BaseFrom):
    post_id = IntegerField(
        label='帖子ID',
        validators=[InputRequired(message='请传入帖子ID')]
    )

class DeleteArticle(AddHighLight):
    pass